Skip to content

Conversation

@elkangaroo
Copy link
Contributor

@elkangaroo elkangaroo commented Jul 12, 2020

WORK IN PROGRESS

Status Quo:

Partly solves #28

Needs more testing!

  • test friends presence with all battle.net games (tested with: Overwatch, StarCraft II, Diablo III, World of Warcraft)
  • test friends presence when friend has battle.net state "dnd" (does it map to gog "away"-state?)
  • test with GOG open for longer time (does it update correctly?)
    • it updates correctly in subsequent "users presence import" from plugin
    • sometimes we receive a disconnect message from battle.net, can we prevent this or try to re-connect?
  • test what happens when authenticated user is logged into Battle.net Mobile App

@elkangaroo elkangaroo force-pushed the feature/friends_presence branch from fbd9747 to 4f43411 Compare July 12, 2020 14:37
@elkangaroo
Copy link
Contributor Author

I rebased the branch and rewrote the socked handling using asyncio.
Now it can handle the echo requests from battle.net server and as a nice side effect is much faster than the previous implementation 🥳

@elkangaroo
Copy link
Contributor Author

Now friends presence works correctly when multiple "game_accounts" are returned (which - from my understanding - means the friend is logged in multiple times [on multiple devices]).
It aggregates them and should return correct state and game.

Needs more testing, but otherwise I am quiet happy with the state of this PR now :)

Copy link
Owner

@bartok765 bartok765 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting me read this tonight, it is nice to read good code and learn something.

I've added some comments and some questions but in fact mostly testing is needed.

request = authentication_service_pb2.LogonRequest()
# request.program = "App"
request.program = "BSAp" # login in as mobile
request.platform = "Win"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean for BSAp ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean is platform="Win" (windows) valid if program stands for Mobile App? Shouldn't be Android or iOS instead?

I know that for now it works, but it may looks... strange for blizzard backend metrics...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I can try different values but don't know what it expects.

# request.program = "App"
request.program = "BSAp" # login in as mobile
request.platform = "Win"
request.locale = "enUS"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now we have no regional info fetched from proto communication so there is no need to specify that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried not sending locale, but then get immediately disconnected.
Do we have the correct value from authentication that we could use? I think we only have "region" ('eu', 'us', ...) so far, right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and the region is partially guessed, as login page require knowing it a priori...
There is https://www.blizzard.com/user but it defaults to en_US for me even if I have different settings (however I know it works for china).

For now I would leave en_US. Then we could ask @wanze for testing the same with china locale - if the rich present text is localized.

@elkangaroo
Copy link
Contributor Author

Thanks @bartok765 for your review. I will look into your comments now.

@elkangaroo
Copy link
Contributor Author

Hey @bartok765 I addressed most of your comments, can you please review again?

Copy link
Owner

@bartok765 bartok765 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some comments, but it looks really nice already!

# request.program = "App"
request.program = "BSAp" # login in as mobile
request.platform = "Win"
request.locale = "enUS"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and the region is partially guessed, as login page require knowing it a priori...
There is https://www.blizzard.com/user but it defaults to en_US for me even if I have different settings (however I know it works for china).

For now I would leave en_US. Then we could ask @wanze for testing the same with china locale - if the rich present text is localized.

request = authentication_service_pb2.LogonRequest()
# request.program = "App"
request.program = "BSAp" # login in as mobile
request.platform = "Win"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean is platform="Win" (windows) valid if program stands for Mobile App? Shouldn't be Android or iOS instead?

I know that for now it works, but it may looks... strange for blizzard backend metrics...

await self._send_message(self._PRESENCE_SERVICE, 4, request, functools.partial(self._on_presence__query_account, future))

async def fetch_friend_presence_account_details(self, account_id, future: asyncio.Future):
async def fetch_friend_presence_account_details(self, entity_id, future: 'asyncio.Future[AccountInfo]'):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can avoid repeating code for fetch_friend_battle_tag and fetch_friend_presence_account_details

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your suggestion @bartok765 ? Maybe just put this in a private function with variable values replaced?

        request = presence_service_pb2.QueryRequest()
        request.entity_id.high = entity_id.high
        request.entity_id.low = entity_id.low
        for i in [...]:
            key = request.key.add()
            key.program = 0x424e  # hex code for "BN"
            key.group = ...
            key.field = i

Or do you have another idea?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group is the same in both methods, so yes - it could be either one private method for basic request with additional parameter of field list to set OR both methods may be just merged into one with additional param. I have no opinion which is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants